/*成绩管理 */
<template>
  <div>
    <div style="height: 30px">
        <el-breadcrumb style="float: left" separator="/">
            <el-breadcrumb-item :to="{ path: '/competitionList' }">
                <span @click="reback()">{{ $t('myResults.competitionList') }}</span>
            </el-breadcrumb-item>
            <el-breadcrumb-item>{{ $t('performanceManagement.competitionManagement') }}</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <condition-card @reset="reset" @search="onSubmit" label-position="right" label-width="150px">
      <el-row :gutter="24" style="height: 50px;">
        <!-- 学号 -->
        <el-col :span="8">
            <el-form-item :label="$t('registrationList.studentId')">
                <el-input v-model.trim="queryForm.condition.studentId" :placeholder="$t('projectInformationStatistics.pleaseEnter')" clearable style="width: 100%" />
            </el-form-item>
        </el-col>
        <!-- 姓名 -->
        <el-col :span="8">
            <el-form-item :label="$t('registrationList.studentName')">
                <el-input v-model.trim="queryForm.condition.studentName" :placeholder="$t('projectInformationStatistics.pleaseEnter')" clearable style="width: 100%" />
            </el-form-item>
        </el-col>
        <!-- 校区 -->
        <el-col :span="8">
            <el-form-item :label="$t('performanceManagement.campus')">
                <DictSelect
                    :filterable="true"
                    v-model="queryForm.condition.campus"
                    :data="options.campus"
                    :clearable="true"
                ></DictSelect>
            </el-form-item>
        </el-col>
        <!-- 竞赛级别 -->
        <!-- <el-col :span="8">
          <el-form-item :label="$t('projectInformationStatistics.competitionLevel')">
            <el-select v-model="queryForm.condition.comLevel"  clearable style="width: 100%">
              <el-option v-for="item in options.degreeType" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col> -->
        <!-- 考场 -->
        <el-col :span="8">
          <el-form-item :label="$t('performanceManagement.room')">
            <el-select collapse-tags  v-model="queryForm.condition.classroomId"  filterable clearable  style="width: 100%">
              <el-option  v-for="item in options.approver" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col><!-- 项目负责人 -->
        <!-- 年度 -->
        <!-- <el-col :span="8">
          <el-form-item :label="$t('collegeFirstTrial.year')">
            <el-date-picker style="width:100%"
              :placeholder="$t('interScoreEntry.pleaseSelect')"
              v-model="queryForm.condition.year"
              type="year" value-format="yyyy" format="yyyy">
            </el-date-picker>
          </el-form-item>
        </el-col> -->
        <!-- 教学班 -->
        <el-col :span="8">
          <el-form-item :label="$t('performanceManagement.teacher')">
            <!-- <el-input
              v-model="queryForm.condition.course" 
              clearable
              :placeholder="$t('projectInformationStatistics.pleaseEnter')" 
              style="width: 100%">
            </el-input> -->
            <el-select
              v-model="queryForm.condition.teacher"
              filterable
              remote
              clearable
              reserve-keyword
              @change="getTeacher"
              style="width: 100%"
              :placeholder="$t('performanceManagement.pleaseInputNumberOrTeacherName')"
              :remote-method="getTeacherInfoList"
              :loading="loading">
              <el-option
                v-for="item in options.teacher"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!-- 教学班 -->
        <el-col :span="8">
          <el-form-item :label="$t('performanceManagement.teachingClass')">
            <!-- <el-input
              v-model="queryForm.condition.course" 
              clearable
              :placeholder="$t('projectInformationStatistics.pleaseEnter')" 
              style="width: 100%">
            </el-input> -->
            <el-select
              v-model="queryForm.condition.teachingClassId"
              filterable
              remote
              clearable
              reserve-keyword
              style="width: 100%"
              :placeholder="$t('performanceManagement.pleaseEnterTheClassName')"
              :remote-method="remoteMethod">
              <el-option
                v-for="item in options.teachingClass"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
              <el-form-item label="学院">
                  <!-- <DictSelect v-model="queryForm.condition.faculty" :data="options.faculty" :clearable="false" ></DictSelect> -->
                  <DictSelect labelAll="请选择" v-model="queryForm.condition.college" filterable @change="changeFaculty" :data="options.faculty" :clearable="true"></DictSelect>
              </el-form-item>
          </el-col>
          <el-col :span="8">
              <el-form-item label="专业 ">
                  <!-- <DictSelect v-model="queryForm.condition.profession" :data="options.profession" :clearable="false" ></DictSelect> -->
                  <DictSelect labelAll="请选择" v-model="queryForm.condition.major" filterable :data="options.profession" :clearable="true" ></DictSelect>
              </el-form-item>
          </el-col>
          <!-- 只展示非教学班学生 -->
          <el-col :span="8">
            <el-form-item :label="$t('performanceManagement.nonTeachingStudents')">
              <el-select
                  :label="$t('performanceManagement.nonTeachingStudents')"
                  style="width:100%"
                  v-model="queryForm.condition.noClass"
                  clearable
              >
                  <el-option
                      v-for="(item,index) in noClass"
                      :key="index"
                      :label="item.label"
                      :value="item.value"
                  ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- 竞赛小类 -->
          <el-col :span="8" v-if="options.subName.length>0">
            <el-form-item :label="$t('registrationList.competitionCate')">
              <el-select v-model="queryForm.condition.subId" clearable style="width: 100%">
                <el-option
                  v-for="item in options.subName"
                  :key="item.id"
                  :label="item.subName"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
      </el-row><!-- 第二行 -->
    </condition-card>



    <el-card shadow="never" v-loading="loading" body-style="padding: 24px;" class="card-margin">
      <h1 class="condition-title">{{$t('performanceManagement.studentList')}}</h1>
        <el-row style="padding:15px;" class="row-bg" justify="space-between">
          <el-button
              type="primary"
              style="float:right; margin-left:10px;"
              @click="exportFile"
            >{{$t('projectInformationStatistics.export')}}</el-button>
          <el-dropdown style="float:right; margin-left:10px;" trigger="click" @command="downloadFile">
            <el-button type="primary">
              {{$t('performanceManagement.import')}}<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="import">{{$t('performanceManagement.importGrades')}}</el-dropdown-item>
              <el-dropdown-item command="downLoad">{{$t('internship.download')}}</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-dropdown style="float:right; margin-left:10px;" trigger="click" @command="downloadFile">
            <el-button type="primary">
              {{$t('performanceManagement.resultsAnnounced')}}<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="publishResults">{{$t('performanceManagement.publishResults')}}</el-dropdown-item>
              <el-dropdown-item command="publishEtc">{{$t('performanceManagement.publishEtc')}}</el-dropdown-item>
              <el-dropdown-item command="publishAll">{{$t('performanceManagement.publishAll')}}</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-button
              style="float:right; margin-left:10px;"
              @click="reback"
            >{{$t('statisticsOfAwards.goBack')}}</el-button>
        </el-row>
        
      <edu-table :pagination="false" :order="false" :selection='true' :tooltipEffect="tooltipEffect" stripe :data="dataList" size="mini" @selection-change="handleSelectionChange">
        <edu-table-column :label="$t('registrationList.orderNum')" prop="sort" ></edu-table-column>
        <edu-table-column :label="$t('registrationList.competitionCate')" prop="subName" v-if="options.subName.length>0"></edu-table-column>
        <edu-table-column :label="$t('registrationList.college')" prop="collegeName"></edu-table-column>
        <edu-table-column :label="$t('competitionRegistrationRules.major')" prop="majorName"></edu-table-column>
        <edu-table-column :label="$t('performanceManagement.admissionCard')" prop="examCardNo"></edu-table-column>
          <edu-table-column :label="$t('performanceManagement.studentName')" prop="studentName">
            <!-- <template slot-scope="props">
              <span v-if="props.row.sex == '2'">女</span>
              <span v-if="props.row.sex == '1'">男</span>
            </template> -->
          </edu-table-column>
          <edu-table-column :label="$t('performanceManagement.studentId')" prop="studentId"></edu-table-column>
          <edu-table-column :label="$t('registrationList.classTeacher')" prop="classTeacher"></edu-table-column>
          <edu-table-column :label="$t('performanceManagement.totalScore')" prop="score"></edu-table-column>
          <edu-table-column :label="$t('performanceManagement.rank')" prop="level"></edu-table-column>
          <edu-table-column :label="$t('collegeFirstTrial.year')" prop="year"></edu-table-column>
          <edu-table-column :label="$t('performanceManagement.examinationStatus')" prop="statusName"></edu-table-column>   
          <edu-table-column :label="$t('performanceManagement.releaseStatusName')" prop="releaseStatusName"></edu-table-column>   
          <edu-table-column :label="$t('performanceManagement.operation')">
            <template slot-scope="props">
              <el-button type="text" @click="submitResults(props.row,props.$index, 'edit')">{{$t('projectDeclara.compile')}}</el-button>
              <el-button type="text" @click="publish(props.row,props.$index, 'publish')">{{$t('performanceManagement.resultsAnnounced')}}</el-button>
            </template>
          </edu-table-column>

      </edu-table>
      <el-row type="flex" class="row-bg" justify="end">
        <el-col>
          <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="queryForm.pageNum_"
              :page-sizes="[20, 40, 80, 100]"
              :page-size="queryForm.pageSize_"
              layout="total, sizes, prev, pager, next, jumper"
              :total="queryForm.total_"
              style="float:right;margin-top:10px"
            ></el-pagination>
        </el-col>
      </el-row>
    </el-card>
    <edu-export-dialog
        :disabled="exportButton"
        :title="$t('message.prompt')"
        ref="downloadRef"
        :data="exportResult">
      </edu-export-dialog>
      <!--批量导入弹窗-->
      <el-dialog
          :title.sync="batchImportDialog.dialogTitle"
          :visible.sync="batchImportDialog.showDialog"
          width="30%"
      >
          <el-form :model="dataObj" :rules="rulesForm" ref="dialog" label-position="right" label-suffix="："  v-if="options.subName && options.subName.length>0">
            <el-form-item :label="$t('registrationList.competitionCate')" prop="subId">
              <el-select v-model="dataObj.subId" @change="changeSubid" clearable style="width: 50%">
                <el-option
                  v-for="item in options.subName"
                  :key="item.id"
                  :label="item.subName"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <el-upload
              :action="importUrl"
              class="upload-demo"
              ref="upload"
              :file-list="batchImportDialog.uploadConfig.fileList"
              :data='dataObj'
              :on-success="handlerSuccess"
              :on-error="handlerError"
              :before-upload="beforeUpload"
              accept="xlsx"
              :auto-upload="true"
              :show-file-list="false"
              :limit="1"
              :disabled="disableButton && options.subName.length > 0"
          >
              <el-button :disabled="disableButton && options.subName.length > 0"  slot="trigger" size="small" type="primary" style="margin-left:200px">{{ $t('statisticsOfAwards.selectFile') }}</el-button>
              <div style="margin-left:28%;margin-top:10px">{{$t('conOfIntAcaCon.uploadNotice')}}</div>
          </el-upload>
            <el-table stripe :data="errList" size="mini" width='100%' v-show="ifErr" tooltip-effect="light">
                <el-table-column
                    :label="$t('performanceManagement.admissionCard')"
                    prop="examCardNo"
                    width="100px"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    :label="$t('performanceManagement.studentName')"
                    prop="studentName"
                    width="100px"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    :label="$t('performanceManagement.studentId')" 
                    prop="studentId"
                    width="100px"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    :label="$t('performanceManagement.totalScore')"
                    prop="score"
                    width="100px"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    :label="$t('performanceManagement.rank')" 
                    prop="level"
                    width="100px"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    :label="$t('performanceManagement.examinationStatus')"
                    prop="status"
                    width="120px"
                    show-overflow-tooltip
                ></el-table-column>
                <!-- 原因 -->
                <el-table-column
                    :label="$t('performanceManagement.reasonsForFailure')"
                    prop="errorMsg"
                    width="120px"
                    show-overflow-tooltip
                ></el-table-column>
            </el-table>
          <span slot="footer" class="dialog-footer">
              <el-button @click="closeDialog">{{ $t('statisticsOfAwards.close') }}</el-button>
          </span>
      </el-dialog>
      <el-dialog :before-close="cancel" :title="dialogTitle" :visible.sync="dialogFormVisible" :dataProp="dataProp" :dataQueryForm="dataQueryForm">
        <el-form :model="form" ref="formName" :rules="rules" v-if="dialogType === 'edit'">
          <!-- 总分 -->
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('performanceManagement.totalScore')" label-width="120px">
                <el-input 
                  type="number"
                  oninput="if(value.length>6)value=value.slice(0,6)"
                  v-model.number="form.score" 
                  maxlength="6" 
                  style="width:50%" 
                  :placeholder="$t('annualTotalBudgetSetting.pleaseEnter')" 
                  clearable 
                  >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 等第 -->
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('performanceManagement.rank')" label-width="120px">
                <el-input style="width:50%" :placeholder="$t('annualTotalBudgetSetting.pleaseEnter')" maxlength="12" v-model="form.level" clearable ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-form :model="form" ref='formName' :rules="rules" v-if="dialogType === 'publish'">
          <el-row>
            <el-col :span="24">
              <el-form-item :label="$t('performanceManagement.resultsAnnounced')" prop="releaseStatus" label-width="120px">
                <el-select
                    :label="$t('performanceManagement.resultsAnnounced')"
                    style="width:50%"
                    v-model="form.releaseStatus"
                    @change="handleSchemeChange"
                    clearable
                >
                    <el-option
                        v-for="(item,index) in publishList"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                    ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancel">{{$t('annualTotalBudgetSetting.cancel')}}</el-button>
          <el-button type="primary" @click="determine('formName')">{{$t('annualTotalBudgetSetting.determine')}}</el-button>
        </div>
      </el-dialog>
  </div>
</template>
<script>
import { queryDic } from "common/src/api/dictionary";
import UTILS from "common/src/utils/utils";
import { findTeacherInfoList } from 'common/src/api/studentinfo';
import competiManagementApi from 'common/src/api/subjectCompetition/competiManagement';
import competitionRegistrationApi from 'common/src/api/competitionRegistration/competitionRegistration';
import comRegistration from 'common/src/api/competitionRegistration/comRegistration'
export default {
  props: {
      compile: {
          type: String,
          default: '',
      },
      dataInfo: {
          type: Object,
          default: () => {},
      },
  },
  data () {
    return {
      disableButton: true,
      errList: [],
      ifErr: false, // 是否展示错误信息
      msg: '',
      queryForm: {
        pageNum_: 1,
        pageSize_: 20,
        total_: 0,
        condition:{
          subId: '',
          // competitionId: this.$route.query.dataInfo.id, // 竞赛id
          competitionId: this.dataInfo.id, // 竞赛id
          studentId: '', // 学号
          studentName: '', // 学生姓名
          classroomId: '', // 考场
          teachingClassId: '', // 开课课程
          campus: '', // 校区
          teacher: '', // 教师
          college: '', // 学院
          major: '', // 专业
          noClass: null // 只展示非教学班学生
        }
      },
      options: {
        subName: [],
        faculty: [], // 学院
        approver: [],
        profession: [], // 竞赛名称
        degreeType: [], // 竞赛级别
        campus: [], // 校区
        teachingClass: [], // 教学班
        teacher: [], // 教师
        profession: [] // 专业
      },

      titleList: '',
      fileList: [],
      showDate: true,
      addflag: false,
      tableFlag: false,
      peopleadd: {},
      dataQueryForm: {},
      curRow: {},
      ifDetials: false,
      copyDialog: false,
      curCalendarId: '',
      isAllDel: true,
      exportButton: false,
      exportResult: null,
      multipleSelection: [],
      formsLearn: [],
      dataList: [],
      breadPath: {
        label: this.$t('graduate.graduate'),
        key: "1",
        children: [
          {
            key: "2",
            label: ""
          }
        ]
      },
      batchImportDialog: {
          dialogTitle: "导入成绩",
          showDialog: false,
          uploadConfig: {
              fileList: [],
              // handlerChange(file, fileList) {
              //     this.fileList = fileList.slice(-1);
              // },
              // handlerExceed(file, fileList) {
              //     this.fileList = fileList.slice(-1);
              // }
          }
      },
      importUrl: '',
      dataObj: {
          competitionId: this.dataInfo.id,
          subId: null
      },
      dialogTitle: '',
      dialogFormVisible: false,
      form: {
        score: '',
        level: '',
        releaseStatus: '',
        id: ''
      },
      rules: {
        score: [
          { required: true, message: this.$t('projectInformationStatistics.pleaseEnter'), trigger: 'blur' }
        ],
        level: [
          { required: true, message: this.$t('projectInformationStatistics.pleaseEnter'), trigger: 'blur' }
        ],
        releaseStatus: [
          { required: true, message: this.$t('interScoreEntry.pleaseSelect'), trigger: 'blur' }
        ]
      },
      rulesForm: {
        subId: [
          { required: true, message: this.$t('registrationList.plzSelectCate'), trigger: 'change' }
        ]
      },
      studentInfo: [], // 学生信息
      dialogType: '',
      publishList: [
        {
          value: '1',
          label: '公布成绩'
        }, {
          value: '2',
          label: '公布等第'
        }, {
          value: '3',
          label: '全部公布'
        }
      ],
      scoreIds: [], // 成绩ids
      isGraduate: false, // 判断是 true研究生还是 false本科生
      calendar: "", //当前学期学年id
      noClass: [
        {
          value: true,
          label: '是'
        }, {
          value: false,
          label: '否'
        }
      ]
    }
  },
  mounted() {
    this.getsubName()
    let user =
      this.$store.state.session.user ||
      JSON.parse(localStorage.getItem("user"))
    if (user && user.currentManageDptId) {
      this.isGraduate = user.currentManageDptId != "1"
    }
    this.getOptions() 
    this.postProjectInform(this.queryForm)
    this.getClassroomList(this.queryForm.condition)
  },
  filters: {
    collegeAcademyList(val, array) {
      let str = "";
      for (let item of array) {
        if (val === item.value) {
          str = item.label;
        }
      }
      return str;
    }
  },
  methods: {
    changeSubid(val) {
      if (val) {
        this.disableButton = false
      } else {
        this.disableButton = true
      }
    },
    closeDialog() {
      this.batchImportDialog.showDialog = false
      if (this.options.subName.length>0) {
        this.$refs['dialog'].resetFields()
      }
      this.dataObj.subId = null
      this.disableButton = true
    },
     // 根据竞赛id获取竞赛小类集合
    getsubName() {
      let jsId = this.queryForm.condition.competitionId // 获得竞赛id
      comRegistration.getSubCompetitions(jsId).then(res => {
          this.options.subName = res.data
      })
    },
    // 字典获取
    getOptions() {
      // 筛选条件字典查询
      let data = {
        lang: this.$store.getters.language || "cn",
        type: "allChild",
        keys: ["X_PYCC", 'X_PYLB', 'X_XWLX', 'X_XXXS', 'X_YX', 'JSGL_JSJB', 'X_XQ', 'G_ZY']
      };
      queryDic(data).then(res => {
        UTILS.fillSelect(
          {
            trainingCategory: "X_PYLB",
            degreeType: "JSGL_JSJB",
            formLearning: "X_XXXS",
            faculty: "X_YX",
            campus: 'X_XQ',
            TrainingLevel: "X_PYCC",
            profession: "G_ZY"
          },
          res.data,
          this.options
        );
      });
    },
    // 学院改变时获取专业
    async changeFaculty(facultys) {
        let _this = this
        this.options.profession = [];
        this.queryForm.condition.major = "";
        const data = {
            lang: this.$store.getters.language || "cn",
            type: "allChild",
            keys: ["G_ZY"],
            filter: {
                prefix: facultys,
                specilaCode: "XY2ZY",
                facultys: facultys
                
            },
            projectId: null
        };
        await this.queryDicM(data,1)
        await this.queryDicM(data,2)
        await this.queryDicM(data,4)
        // this.initData();
    },
    async queryDicM(data,projectId) {
      let _this = this
      data.projectId = projectId
      await queryDic(data).then(res => {
            if (res.code == 200){
              let resp = res.data['G_ZY']
                // UTILS.fillSelect({profession: "G_ZY"},res.data,this.options );
              if(_this.options.profession.length > 0 && resp) {
                let arr = []
                for(let y = 0; y < _this.options.profession.length; y ++) {
                  arr.push(_this.options.profession[y].key)
                }
                for(let j in resp) {
                    if(!arr.includes(j)) {
                      _this.options.profession.push(
                          {
                            label: resp[j] + '('+ j + ')',
                            value: j,
                            key: j
                          }
                        )
                    }
                  }
              } else if(this.options.profession.length === 0 && resp) {
                for(let key in resp) {
                  this.options.profession.push(
                    {
                      label: resp[key] + '(' + key + ')',
                      value: key,
                      key: key
                    }
                  )
                }
              }  
            }
        });
    },
    // 考场
    getClassroomList(data) {
        this.options.approver = []
        competitionRegistrationApi.getClassroomList(data).then(res => {
            // this.dataList = res.data.list
            // this.queryForm.total_ = res.data.total_
            if (res.data) {
              res.data.forEach(el => {
                this.options.approver.push({
                  label: el.roomName,
                  value: el.classroomId
                })
              })
            }
        })
    },
    postProjectInform(data) {
        competitionRegistrationApi.getListPage(data).then(res => {
            this.dataList = res.data.list
            this.queryForm.total_ = res.data.total_
        })
    },
    // 教师下拉
    async getTeacherInfoList(queryForm) {
        let param = {
            "pageNum_": 1,
            "pageSize_": 10,
            "total": 0,
            "condition": queryForm
        }
        this.options.teacher = []
        try {
            let resp = await findTeacherInfoList(param)
            if (resp && resp.data && resp.code == 200) {
                // this.options.teacher = resp.data.list || []
                // this.teacherForm.total = resp.data.total || 0
                if (resp.data.list) {
                    resp.data.list.forEach(el => {
                        this.options.teacher.push({
                            label: el.name + '('+ el.code + ')',
                            value: el.code
                        })
                    })
                }
            } else {
                this.setDataFormatErrMsg()
            }
        } catch (error) {
            console.log(error)
        }
    },
    // 获取教师
    getTeacher(value) {
      if(value) {
        this.remoteMethod('')
      }
    },
    // 错误信息
    setDataFormatErrMsg() {
        this.$message({
            type: 'error',
            message: 'The data returned is malformed',
        })
    },
    // 教学班下拉
    remoteMethod(query) {
      let param = {
          "pageNum_":1,
          "pageSize_":10,
          "condition":{
              "calendar": this.dataInfo.calendarId,
              "trainingLevelList": this.isGraduate === true ? [4,6] : [1,5],
              "teacherCode": this.queryForm.condition.teacher,
              "keyword": query
          }
      }
      this.options.teachingClass = []
      if(this.queryForm.condition.teacher) {
        competitionRegistrationApi.getTeachingClass(param).then(res => {
            if (res.data.list) {
                res.data.list.forEach(el => {
                    this.options.teachingClass.push({
                        label: el.courseName + '('+ el.code + ')',
                        value: el.id
                    })
                })
            }
        })
      }
    },
    // 筛选
    onSubmit() {
      this.queryForm.pageNum_ = 1
      this.postProjectInform(this.queryForm)
    },
    // 重置
    reset() {
      for (let key in this.queryForm.condition) {
        if (key === 'competitionId' || key === 'year') {
            continue;
        }
        this.queryForm.condition[key] = '';
      }
      // this.queryForm.condition.year = new Date().getFullYear()+''
      this.options.approver = []
      this.queryForm.pageNum_ = 1
      this.postProjectInform(this.queryForm)
    },
    // 轮询直到获取key值的接口返回
    cycleToGetKey() {
      setTimeout(() => {
        competiManagementApi.projectInformaExport({
          "college": this.queryForm.condition.college,
          "name": this.queryForm.condition.name,
          "comLevel": this.queryForm.condition.comLevel,
          "comManager": this.queryForm.condition.classroomId
        }).then(res => {
          if (res.success) {
            this.$refs.downloadRef.close();
            this.exportButton = false;
            this.normalDelayRequest(res.key, res.msg);
          } else {
            this.cycleToGetKey();
          }
        });
      }, 3000);
    },
    // 导出异步
    delayRequest(key, name) {
      setTimeout(() => {
        competiManagementApi.downloadGetKey(key, name).then(res => {
          this.exportResult = res.data;
          if (res.code == 200 && res.data.status) {
            this.exportButton = false;
            let path = '/api/competitionservice/competitionExport/file?path=' + res.data.path + '&name=' + name;
            // window.open(path);
            window.location.href = path;
            this.$message.success(this.$t('result.exportSuccessfully'));
            this.$refs.downloadRef.close();
          } else {
            this.delayRequest(key, name);
          }
        });
      }, 3000);
    },
    // Normal导出异步
    normalDelayRequest(key, name) {
      setTimeout(() => {
        competiManagementApi.downloadGetKey(key).then(res => {
          this.exportResult = res.data;
          if (res.code == 200 && res.data.status) {
            this.exportButton = false;
            let path =  '/api/competitionservice/competitionExport/file?path=' + res.data.path + '&name=' + name;
            window.location.href = path;
            this.$message.success(this.$t('result.exportSuccessfully'));
            this.$refs.downloadRef.close();
          } else {
            this.delayRequest(key, name);
          }
        });
      }, 3000);
    },
    //  导出
    exportFile() {
      // 1、第一步：调该接口，获取key值以及msg中的文件名
      // 2、第二步：将key值放入接口传参
      // 3、第三步：传入path值以及name(msg中的文件名)值，下载文件
      // this.exportResult = null;
      // this.$refs.downloadRef.open();
      // this.exportButton = true;
      // this.cycleToGetKey();
      let param = {
        "records": this.studentInfo,
        "condition": {
          "competitionId": this.queryForm.condition.competitionId, // 竞赛id
          "studentId": this.queryForm.condition.studentId, // 学号
          "studentName": this.queryForm.condition.studentName, // 学生姓名
          "classroomId": this.queryForm.condition.classroomId, // 考场
          "teachingClassId": this.queryForm.condition.teachingClassId, // 开课课程
          "campus": this.queryForm.condition.campus, // 校区
          "teacher": this.queryForm.condition.teacher, // 教师
          "college": this.queryForm.condition.college, // 学院
          "major": this.queryForm.condition.major, // 专业
          "noClass": this.queryForm.condition.noClass // 只展示非教学班学生
        }
      }
      competitionRegistrationApi.exportList(param)
    },
    handleSelectionChange(val) {
      this.studentInfo = val
    },
    handleSizeChange(val) {
      this.queryForm.pageSize_ = val
      this.queryForm.pageNum_ = 1
      this.postProjectInform(this.queryForm)
    },
    handleCurrentChange(val) {
      this.queryForm.pageNum_ = val
      this.postProjectInform(this.queryForm)
    },
    // 下载模板、导入数据
    downloadFile(command) {
        this.studentInfo.forEach( item => {
            this.scoreIds.push(item.id)
        })
        if (command === 'import') {
            this.importUrl = 'api/competitionservice/sign/scoreManage/importScore'
            this.errList = []
            this.ifErr = false
            this.batchImportDialog.showDialog = true
        } else if (command === 'downLoad') {
            competitionRegistrationApi.downTemplate().then(res => {
                this.batchImportDialog.showDialog = false
                this.$message.success(this.$t('internship.successfully'))
            });
        } else if (command === 'publishResults') {
            let params = {
                "competitionId": this.queryForm.condition.competitionId,
                "releaseStatus": '1',
                "ids": this.scoreIds.toString()
            }
            this.$confirm(this.$t('performanceManagement.surePublishResults'), '提示', {
            confirmButtonText: this.$t('competitionRegistrationRules.determine'),
            cancelButtonText: this.$t('competitionRegistrationRules.cancel'),
            type: 'warning'
            }).then(() => {
              competitionRegistrationApi.batchPublishScore(params).then(res => {
                    this.batchImportDialog.showDialog = false
                    this.$message.success(this.$t('internship.successfully'))
                    this.postProjectInform(this.queryForm)
                    this.scoreIds = []
                })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: this.$t('performanceManagement.haveCancel')
              });          
            });
            
        } else if (command === 'publishEtc') {
            let params = {
                "competitionId": this.queryForm.condition.competitionId,
                "releaseStatus": '2',
                "ids": this.scoreIds.toString()
            }
            this.$confirm(this.$t('performanceManagement.surePublishEtc'), '提示', {
            confirmButtonText: this.$t('competitionRegistrationRules.determine'),
            cancelButtonText: this.$t('competitionRegistrationRules.cancel'),
            type: 'warning'
            }).then(() => {
              competitionRegistrationApi.batchPublishScore(params).then(res => {
                this.batchImportDialog.showDialog = false
                this.$message.success(this.$t('internship.successfully'))
                this.postProjectInform(this.queryForm)
                this.scoreIds = []
            })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: this.$t('performanceManagement.haveCancel')
              });          
            });
            
        } else if (command === 'publishAll') {
            let params = {
                "competitionId": this.queryForm.condition.competitionId,
                "releaseStatus": '3',
                "ids": this.scoreIds.toString()
            }
            this.$confirm(this.$t('performanceManagement.surePublishAll'), '提示', {
            confirmButtonText: this.$t('competitionRegistrationRules.determine'),
            cancelButtonText: this.$t('competitionRegistrationRules.cancel'),
            type: 'warning'
            }).then(() => {
              competitionRegistrationApi.batchPublishScore(params).then(res => {
                this.batchImportDialog.showDialog = false
                this.$message.success(this.$t('internship.successfully'))
                this.postProjectInform(this.queryForm)
                this.scoreIds = []
            })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: this.$t('performanceManagement.haveCancel')
              });          
            });
            
        }
    },
    handlerSuccess(response, file, fileList) {
        let responseCode = response.code
        if (responseCode === 200) {
            this.batchImportDialog.uploadConfig.fileList = [];
            this.queryForm.pageNum_ = 1
            this.postProjectInform(this.queryForm)
            this.$message({
                message: this.$t('statisticsOfAwards.uploadSuccessful'),
                type: "success"
            });
            this.batchImportDialog.showDialog = false
            if (this.options.subName.length>0) {
              this.$refs['dialog'].resetFields()
            }
            this.dataObj.subId = null
            this.disableButton = true
            // this.onSubmit();
        } else {
            this.batchImportDialog.uploadConfig.fileList = [];
            if (response.data) {
                this.errList = response.data
                this.ifErr = true
                this.$message({type: "info", message: this.$t('statisticsOfAwards.addedFully')});
            } else {
                this.$message({type: "info", message: response.msg});
            }
        }
    },
    handlerError(rresponse, file, fileList) {
        this.batchImportDialog.uploadConfig.fileList = [];
        this.$message({
            message: this.$t('statisticsOfAwards.uploadFailed'),
            type: "error"
        });
        this.batchImportDialog.showDialog = false
    },
    // 编辑
    submitResults(data, index, type) {
      this.dialogType = type
      this.dialogTitle = this.$t('performanceManagement.edit')
      this.dialogFormVisible = true
      this.form.score = data.score
      this.form.level = data.level
      this.form.id = data.id
      // this.queryForm.lastScoreList[index].flag = false
    },
    // 公布成绩
    publish(data, index, type) {
      this.dialogType = type
      this.dialogTitle = this.$t('performanceManagement.resultsAnnounced')
      this.dialogFormVisible = true
      this.form.id = data.id
    },
    // 取消
    cancel() {
      for (let key in this.form) {
        this.form[key] = ''
      }
      this.$refs['formName'].resetFields()
      this.dialogFormVisible = false
      this.dialogType = ''
    },
    // 确定
    determine(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
            if (this.dialogType === 'edit') {
                this.validateWeight(this.form.score)
                if(this.msg) {
                  this.$message.error(this.msg)
                  return false
                }
                competitionRegistrationApi.scoreManageEdit(this.form).then(res =>{
                  this.$message({type: "success", message: this.$t('internship.successfully')})
                  this.dialogFormVisible = false
                  this.$refs['formName'].resetFields()
                  this.queryForm.pageNum_ = 1
                  this.postProjectInform(this.queryForm)
                  this.dialogType = ''
                })
            } else if(this.dialogType === 'publish') {
                competitionRegistrationApi.publishSingleScore(this.form).then(res =>{
                  this.$message({type: "success", message: this.$t('internship.successfully')})
                  this.dialogFormVisible = false
                  this.$refs['formName'].resetFields()
                  this.queryForm.pageNum_ = 1
                  this.postProjectInform(this.queryForm)
                  this.dialogType = ''
                })
            }
        }
      })
    },
    validateWeight(valOne) {
      // debugger
      this.msg = ''
      if ((valOne >= 0 && valOne < 1000)) {
          let expReg = /^\d{1,3}(\.\d{1,2})?$/  // 最多为3位整数2位小数
          if (!expReg.test(valOne)) {
              this.msg = this.$t('performanceManagement.limitIntegers')
          } 
      }else {
          this.msg = this.$t('performanceManagement.pleaseEnterIntegers')
      }
      if (valOne === '' || valOne === null) {
        this.msg = ''
      }
    },
    // 返回主页面
    reback() {
        this.$emit('change-exam')
    },
  }
}
</script>
<style lang="scss" scoped>
.el-breadcrumb__item:last-child ::v-deep {
    .el-breadcrumb__inner {
        color: #606266;
        font-weight: bold;
        cursor: default;
    }
}
.el-breadcrumb__item ::v-deep {
    .is-link {
        color: #aaa;
        font-weight: unset;
    }
    .is-link:hover {
        color: #409eff;
    }
}
</style>